﻿using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;

namespace LMSData
{

    public partial class AssessmentResponseController
    {
        public AssessmentResponseCollection Fetch(int CourseID, string UserName, int AssessmentID)
        {
            UserAssessment ua = new UserAssessment();
            UserCollection uc = new UserCollection();
            Query uq = new Query(User.Schema).WHERE(User.Columns.Username, UserName).WHERE(User.Columns.IsDeleted, false);
            uc.LoadAndCloseReader(uq.ExecuteReader());

            int UserID = -1;
            if (uc.Count > 0)
                UserID = uc[0].UserID;

            UserAssessmentCollection coll = new UserAssessmentCollection();
            Query qry = new Query(UserAssessment.Schema);
            qry.AddWhere(UserAssessment.Columns.CourseID, CourseID);
            qry.AddWhere(UserAssessment.Columns.UserID, UserID);
            qry.AddWhere(UserAssessment.Columns.AssessmentID, AssessmentID);
            qry.AddWhere(UserAssessment.Columns.IsDeleted, false);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            if (coll.Count > 0)
                ua = coll[0];
            else
                return new AssessmentResponseCollection();

            AssessmentResponseCollection arc = new AssessmentResponseCollection();
            qry = new Query(AssessmentResponse.Schema);
            qry.AddWhere(AssessmentResponse.Columns.UserAssessmentID, ua.UserAssessmentID);
            qry.AddWhere(AssessmentResponse.Columns.IsDeleted, false);
            arc.LoadAndCloseReader(qry.ExecuteReader());
            return arc;
        }

        public AssessmentResponseCollection Fetch(int AssessmentItemID)
        {
            AssessmentResponseCollection arc = new AssessmentResponseCollection();
            Query qry = new Query(AssessmentResponse.Schema);
            qry.AddWhere(AssessmentResponse.Columns.AssessmentItemID, AssessmentItemID);
            qry.AddWhere(AssessmentResponse.Columns.IsDeleted, false);
            arc.LoadAndCloseReader(qry.ExecuteReader());
            return arc;
        }
    }
}
